package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.page.PageResult;
import cn.wolfcode.crm.query.EmployeeQuery;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IEmployeeService;
import cn.wolfcode.crm.util.JSONResult;
import cn.wolfcode.crm.util.RequiredPermission;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/employee")
public class EmployeeController {
    @Autowired
    private IEmployeeService employeeService;
    @RequestMapping("")
    public String index(){
        return "employee_list";
    }

    @RequestMapping("/list")
    @ResponseBody
    @RequiresPermissions("employee:list")
    @RequiredPermission("员工列表")
    public PageResult list(EmployeeQuery qo){
        PageResult pageResult =  employeeService.query(qo);
        return pageResult;
    }
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    @RequiresPermissions("employee:saveOrUpdate")
    @RequiredPermission("员工新增")
    public JSONResult saveOrUpdate(Employee employee){

        employeeService.saveOrUpdate(employee);
        return new JSONResult("保存成功");
    }

    @RequestMapping("/updateState")
    @ResponseBody
    @RequiresPermissions("employee:updateState")
    @RequiredPermission("员工离职")
    public JSONResult updateState(Long id){
        employeeService.updateState(id);
        return new JSONResult("离职成功");
    }
}
